package o;

import java.io.EOFException;
import java.io.IOException;
import java.util.zip.CRC32;
import java.util.zip.Inflater;

public final class fxo implements fxw {
    private final fxk ˊ;
    private int ˋ = 0;
    private final Inflater ˎ;
    private final fxg ˏ;
    private final CRC32 ॱ = new CRC32();

    public fxo(fxw o_fxw) {
        if (o_fxw == null) {
            throw new IllegalArgumentException("source == null");
        }
        this.ˎ = new Inflater(true);
        this.ˏ = fxr.ˎ(o_fxw);
        this.ˊ = new fxk(this.ˏ, this.ˎ);
    }

    public long ˊ(fxi o_fxi, long j) throws IOException {
        if (j < 0) {
            throw new IllegalArgumentException("byteCount < 0: " + j);
        } else if (j == 0) {
            return 0;
        } else {
            if (this.ˋ == 0) {
                ˋ();
                this.ˋ = 1;
            }
            if (this.ˋ == 1) {
                long j2 = o_fxi.ˎ;
                long ˊ = this.ˊ.ˊ(o_fxi, j);
                if (ˊ != -1) {
                    ˊ(o_fxi, j2, ˊ);
                    return ˊ;
                }
                this.ˋ = 2;
            }
            if (this.ˋ == 2) {
                ॱ();
                this.ˋ = 3;
                if (!this.ˏ.ᐝ()) {
                    throw new IOException("gzip finished without exhausting source");
                }
            }
            return -1;
        }
    }

    private void ˋ() throws IOException {
        Object obj;
        long ॱ;
        this.ˏ.ˎ(10);
        byte ॱ2 = this.ˏ.ˏ().ॱ(3);
        if (((ॱ2 >> 1) & 1) == 1) {
            obj = 1;
        } else {
            obj = null;
        }
        if (obj != null) {
            ˊ(this.ˏ.ˏ(), 0, 10);
        }
        ˊ("ID1ID2", 8075, this.ˏ.ॱˊ());
        this.ˏ.ʼ(8);
        if (((ॱ2 >> 2) & 1) == 1) {
            this.ˏ.ˎ(2);
            if (obj != null) {
                ˊ(this.ˏ.ˏ(), 0, 2);
            }
            short ˊॱ = this.ˏ.ˏ().ˊॱ();
            this.ˏ.ˎ((long) ˊॱ);
            if (obj != null) {
                ˊ(this.ˏ.ˏ(), 0, (long) ˊॱ);
            }
            this.ˏ.ʼ((long) ˊॱ);
        }
        if (((ॱ2 >> 3) & 1) == 1) {
            ॱ = this.ˏ.ॱ((byte) 0);
            if (ॱ == -1) {
                throw new EOFException();
            }
            if (obj != null) {
                ˊ(this.ˏ.ˏ(), 0, 1 + ॱ);
            }
            this.ˏ.ʼ(1 + ॱ);
        }
        if (((ॱ2 >> 4) & 1) == 1) {
            ॱ = this.ˏ.ॱ((byte) 0);
            if (ॱ == -1) {
                throw new EOFException();
            }
            if (obj != null) {
                ˊ(this.ˏ.ˏ(), 0, 1 + ॱ);
            }
            this.ˏ.ʼ(1 + ॱ);
        }
        if (obj != null) {
            ˊ("FHCRC", this.ˏ.ˊॱ(), (short) ((int) this.ॱ.getValue()));
            this.ॱ.reset();
        }
    }

    private void ॱ() throws IOException {
        ˊ("CRC", this.ˏ.ˏॱ(), (int) this.ॱ.getValue());
        ˊ("ISIZE", this.ˏ.ˏॱ(), (int) this.ˎ.getBytesWritten());
    }

    public fxv ˊ() {
        return this.ˏ.ˊ();
    }

    public void close() throws IOException {
        this.ˊ.close();
    }

    private void ˊ(fxi o_fxi, long j, long j2) {
        fxt o_fxt = o_fxi.ॱ;
        while (j >= ((long) (o_fxt.ˋ - o_fxt.ˎ))) {
            j -= (long) (o_fxt.ˋ - o_fxt.ˎ);
            o_fxt = o_fxt.ʼ;
        }
        while (j2 > 0) {
            int i = (int) (((long) o_fxt.ˎ) + j);
            int min = (int) Math.min((long) (o_fxt.ˋ - i), j2);
            this.ॱ.update(o_fxt.ˏ, i, min);
            j2 -= (long) min;
            o_fxt = o_fxt.ʼ;
            j = 0;
        }
    }

    private void ˊ(String str, int i, int i2) throws IOException {
        if (i2 != i) {
            throw new IOException(String.format("%s: actual 0x%08x != expected 0x%08x", new Object[]{str, Integer.valueOf(i2), Integer.valueOf(i)}));
        }
    }
}
